#!/bin/bash -ex

source /usr/sbin/get_hive_home.sh

cd /home/jenkins
# Download dataset and upload it to HDFS
unzip AirlinesTest.csv.zip
rm AirlinesTest.csv.zip
sed -i 's/\"//g' AirlinesTest.csv
sudo -E -u hive hadoop fs -put -f ./AirlinesTest.csv /tmp/AirlinesTest.csv
sudo -E -u hive hadoop fs -put -f ./chicagoCensus.csv /tmp/chicagoCensus.csv
rm *.csv

# Execute all hive-scripts
cd /opt/hive-scripts
KRB_SUFFIX=
if [ "${KRB_ENABLED}" = "true" ]; then
    KRB_SUFFIX=';principal=hive/localhost@H2O.AI'
fi
for f in $(ls *.hql); do
    sudo -E -u hive ${HIVE_HOME}/bin/beeline -u "jdbc:hive2://localhost:10000/${KRB_SUFFIX}" -f ${f}
done
